package com.shine.app.commons;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.Toast;

import com.shine.app.AppManager;
import com.shine.app.R;
import com.shine.app.ui.ExitDialogActivity;
import com.shine.app.ui.LoginActivity;
import com.shine.app.ui.SearchTeeTimeActivity;
import com.shine.app.ui.ToastDialogActivity;

public class UIHelper {

	public static void showHome(Activity activity) {
		Intent intent = new Intent(activity, SearchTeeTimeActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		activity.startActivity(intent);
		AppManager.getAppManager().finishActivity(activity);
	}

	public static void showLogin(Activity activity) {
		Intent intent = new Intent(activity, LoginActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		activity.startActivity(intent);
	}

	public static void exitDialog(Activity activity) {
		Intent intent = new Intent(activity, ExitDialogActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		activity.startActivity(intent);
	}

	public static void toastMessage(Context context, String message) {
		Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
	}

	public static void toastMessage(Context context, int message) {
		Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
	}

	public static void toastMessage(Context context, String message, int time) {
		Toast.makeText(context, message, time).show();
	}

	public static void sendAppCrashReport(final Activity context,
			final String crashReport) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setIcon(android.R.drawable.ic_dialog_info);
		builder.setTitle(R.string.exception);
		builder.setMessage(R.string.exception_msg);
		builder.setNegativeButton(R.string.msg_yes,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						AppManager.getAppManager().AppExit(context);
					}
				});
		builder.show();
	}

	public static void errorDialog(final Context context) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(R.string.msg_json);
		builder.setPositiveButton(R.string.msg_yes,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						AppManager.getAppManager().AppExit(context);
					}
				});
		builder.create().show();
	}

	public static void toastDialog(final Context context, int title, int button) {
		Intent intent = new Intent(context, ToastDialogActivity.class);
		String message = context.getResources().getString(title);
		String string = context.getResources().getString(button);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		intent.putExtra("title", message);
		intent.putExtra("button", string);
		context.startActivity(intent);
	}

	public static void toastDialogs(final Context context, String title,
			int button) {
		Intent intent = new Intent(context, ToastDialogActivity.class);
		String string = context.getResources().getString(button);
		intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
		intent.putExtra("title", title);
		intent.putExtra("button", string);
		context.startActivity(intent);
	}

}
